<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
        社区管理
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/css/main.css" media="all">
    <script type="text/javascript" src="/lib/loading/okLoading.js"></script>
    <!-- 引入ElementUI样式 -->
    <link rel="stylesheet" href="/css/index.css">
</head>
<body>
<div id="app">

    <div class="x-body">
        <el-form :model="repair" :rules="rules" ref="repairFormRef" label-width="120px" class="demo-ruleForm">

            <el-form-item label="所属社区" prop="communityName">
                <el-input v-model="repair.communityName"></el-input>
            </el-form-item>
            <el-form-item label="所属楼栋" prop="buildingName">
                <el-input v-model="repair.buildingName"></el-input>
            </el-form-item>
            <el-form-item label="业主" prop="ownerName">
                <el-input v-model="repair.ownerName"></el-input>
            </el-form-item>
            <el-form-item label="设备名称" prop="facilities">
                <el-input v-model="repair.facilities"></el-input>
            </el-form-item>
            <el-form-item label="报修描述" prop="remark">
                <el-input
                        type="textarea"
                        :rows="5"
                        placeholder="请输入报修描述内容"
                        v-model="repair.remark">
                </el-input>
            </el-form-item>


            <el-button type="primary" @click="save()" style="text-align: center">保存</el-button>
<!--            <el-button @click="clearAll()" style="text-align: center">重置</el-button>-->

        </el-form>
    </div>
</div>
<script src="lib/layui/layui.js" charset="utf-8"></script>
<script src="js/x-layui.js" charset="utf-8"></script>
<!--导入Vue依赖包-->
<script src="/js/vue.js" charset="utf-8"></script>
<!-- 引入Element组件库 -->
<script src="/js/index.js"></script>
<!--导入Axios依赖包-->
<script src="/js/axios.js" charset="utf-8"></script>
<script type="text/javascript">
    var app = new Vue({
        el:"#app",
        data:{
            title:"添加报修建议",
            repair:{id:""},
            rules: {
                communityName: [
                    { required: true, message: '请输入社区名称', trigger: 'blur' },
                    { max: 50, message: '长度小于50个字符', trigger: 'blur' }
                ],
                buildingName: [
                    { required: true, message: '请输入楼栋名称', trigger: 'blur' },
                    { max: 50, message: '长度小于50个字符', trigger: 'blur' }
                ],
                ownerName: [
                    { required: true, message: '请输入业主名称', trigger: 'blur' },
                    { max: 4, message: '长度小于4个字符', trigger: 'blur' }
                ],
                deviceName: [
                    { required: true, message: '请输入设施名称', trigger: 'blur' },
                    { max: 10, message: '长度小于10个字符', trigger: 'blur' }
                ],
                remark: [
                    { required: true, message: '请输入维修描述', trigger: 'blur' },
                    { max: 10, message: '长度小于100个字符', trigger: 'blur' }
                ]
            }
        },
        methods:{
            save(){
                var method = "";
                if(this.repair.id != null){
                    method = "update"
                }else{
                    method = "add"
                }
                axios.post("/repair/"+method,this.repair).then((res)=>{
                    if(res.data.flag){
                        this.$message({
                            message: res.data.message,
                            type: 'success'
                        });
                    }
                });
            },

            getQueryString(name){
                let reg = `(^|&)${name}=([^&]*)(&|$)`
                let r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]); return null;
            }
        },
        created:function(){
            layui.use(['element','layer','form'], function(){
                $ = layui.jquery;//jquery
                lement = layui.element();//面包导航
                layer = layui.layer;//弹出层
                form = layui.form();
                okLoading.close($);
            });


            //获取父页面传递参数，社区ID
            this.repair.id = this.getQueryString("id");
            //根据社区ID获取社区对象，进行数据回显
            if(this.repair.id != null && this.repair.id != ''){
                this.title="修改xxx";
                this.findById();
            }
        }
    });
</script>
</body>
</html>